package com.fate.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fate.domain.Notice;
import com.fate.service.NoticeService;
import com.fate.vo.NoticeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/shop/notice")
@Api(tags = "公告管理接口")
public class NoticeController {
    @Autowired
    private NoticeService noticeService;

    /**
     * 分页查询公告
     */
    @GetMapping("page")
    @ApiOperation("分页查询公告")
    @PreAuthorize("hasAuthority('shop:notice:page')")
    public ResponseEntity<Page<Notice>> findNoticePage(Page<Notice>page,Notice notice){
        Page<Notice> noticePage = noticeService.findNoticePage(page,notice);
        return ResponseEntity.ok(noticePage);
    }

    /**
     * 查询前台公告列表
     */
    @GetMapping("topNoticeList")
    @ApiOperation("查询前台公告列表")
    public ResponseEntity<List<NoticeVo>> loadFrontNotice(){
        List<NoticeVo> noticeVos =noticeService.loadFrontNotice();
        return ResponseEntity.ok(noticeVos);
    }
}
